local shiyi = fk.CreateSkill{
  name = "hanqing__shiyi",
  tags = { Skill.Limited },
}

Fk:loadTranslationTable{
  ["hanqing__shiyi"] = "市义",
  [":hanqing__shiyi"] = "限定技，出牌阶段，你可以令所有受伤角色将手牌数调整至体力上限，每名因此获得至少两张牌的角色可以令你摸一张牌。",

  ["#hanqing__shiyi"] = "市义：令所有受伤角色将手牌调整至体力上限！",
  ["#hanqing__shiyi-draw"] = "市义：是否令 %src 摸一张牌？",
}

shiyi:addEffect("active", {
  anim_type = "control",
  card_num = 0,
  target_num = 0,
  prompt = "#hanqing__shiyi",
  card_filter = Util.FalseFunc,
  can_use = function(self, player)
    return player:usedSkillTimes(shiyi.name, Player.HistoryGame) == 0 and
      table.find(Fk:currentRoom().alive_players, function (p)
        return p:isWounded()
      end)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local targets = table.filter(room:getAlivePlayers(), function (p)
      return p:isWounded()
    end)
    room:doIndicate(player, targets)
    for _, p in ipairs(targets) do
      if not p.dead then
        local n = p.maxHp - p:getHandcardNum()
        if n > 0 then
          p:drawCards(n, shiyi.name)
          if n > 1 and not p.dead and not player.dead and
            room:askToSkillInvoke(p, {
              skill_name = shiyi.name,
              prompt = "#hanqing__shiyi-draw:"..player.id,
            }) then
            player:drawCards(1, shiyi.name)
          end
        elseif n < 0 then
          room:askToDiscard(p, {
            min_num = -n,
            max_num = -n,
            include_equip = false,
            skill_name = shiyi.name,
            cancelable = false,
          })
        end
      end
    end
  end,
})

return shiyi
